package com.xiantm.study.thread.guardedsuspension;

import java.util.Random;

public class ClientThread extends Thread{
    private int number = 0;
    private final Random random;
    private final RequestQueue queue;

    public ClientThread(String name, RequestQueue queue, long seed){
        super(name);
        this.random = new Random(seed);
        this.queue = queue;
    }

    @Override
    public void run() {
        while (true){
            Request request = new Request("number." + number++, number);
            System.out.println(Thread.currentThread().getName() + " requests " + request.getName() + ".");
            queue.putRequest(request);
            try {
                sleep(random.nextInt(1000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
